<?php
namespace App\Actions;

use App\Models\AdminUser;
use App\Models\Department;
use Illuminate\Support\Facades\Log;

class DepartmentAction extends BaseAction
{
    public $department;
    public $admin_user;

    public function __construct(Department $department = null, AdminUser $adminUser = null)
    {
        $this->department = $department;
        $this->admin_user = $adminUser;
    }

    public function verify($status, $fail_reason = '')
    {
        $this->department->update(['status' => $status, 'fail_reason' => $fail_reason]);
        $messageTitle = '单位材料上传审核通知';
        $result_text = isset(Department::$statusMaps[$status]) ? Department::$statusMaps[$status] : '未知';
        $fail_reason_text = $fail_reason ? "，原因：". $fail_reason : '';
        $messageContent = "您上传的材料审核结果：" .$result_text . $fail_reason_text;

        if ($this->department->type == Department::TYPE_BZ) {
            $department_admin_user = AdminUser::findByDwdm($this->department->dwdm);
        } else {
            $department_admin_user = AdminUser::findByDdbDwdm($this->department->dwdm);
        }
        if (!$department_admin_user || ($department_admin_user && !$department_admin_user->phone)) {
            return;
        }
        try {
            SmsPoolAction::make()->pushPool(['phone' => $this->admin_user->phone, 'title' => $messageTitle, 'content' => $messageContent], $this->department);
        } catch (\Throwable $th) {
            
        }
        
    }

    
}